package com.sjb.mianshiya.satoken;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import com.sjb.mianshiya.model.domain.User;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

import static com.sjb.mianshiya.contant.UserConstant.USER_LOGIN_STATE;

/**
 * @Author:sjb
 * @CreateTime:2024-11-21
 * @Description: saToken鉴权
 * @Version：1.0
 */
@Component
public class StpInterfaceImpl implements StpInterface {


    /**
     * 返回一个账号所拥有的权限码集合
     * @param loginId  账号id
     * @param loginType 账号类型
     * @return
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return Collections.emptyList();
    }

    /**
     * 从当前登录用户信息中获取角色信息
     * @param loginId  账号id
     * @param loginType 账号类型
     * @return
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        User user =(User) StpUtil.getSessionByLoginId(loginId).get(USER_LOGIN_STATE);
        return Collections.singletonList(user.getUserrole());
    }
}
